﻿<UserControl x:Class="SimpleDbBrowser.UserControls.CustomSelectUserControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             MinHeight="300" MaxHeight="300"
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Label Grid.Row="0" Grid.Column="0" Content="Custom Query:" />
        <DockPanel Grid.Row="4" Grid.Column="1">
            <Label DockPanel.Dock="Right" Content="{Binding ResultCount}" ContentStringFormat="}{0}}" HorizontalContentAlignment="Right" />
            <Label Content="Attributes: " HorizontalContentAlignment="Right" />
        </DockPanel>
        <TextBox Grid.Row="0" Grid.Column="1"
                 Text="{Binding Path=Query, UpdateSourceTrigger=PropertyChanged}" AcceptsReturn="True" MaxLength="4096" 
                 MinWidth="75" 
                 TextWrapping="WrapWithOverflow" 
                 HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" 
                 MaxLines="3" MinLines="3" />
        <Button Grid.Row="1" Grid.ColumnSpan="2" Content="Execute Custom Query" Command="{Binding SubmitCustomQuery}" />
        <Label Grid.Row="2" Grid.ColumnSpan="2" x:Name="lblErr" Content="{Binding ErrorMessage}" FontWeight="Bold">
            <Label.Style>
                <Style>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding ErrorMessage}" Value="{x:Null}" >
                            <Setter Property="Label.Visibility" Value="Collapsed" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Label.Style>
        </Label>
        <ListView Grid.Row="3" Grid.ColumnSpan="2" ItemsSource="{Binding QueryResults}">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Item name" DisplayMemberBinding="{Binding Item1}" />
                    <GridViewColumn Header="Attribute name" DisplayMemberBinding="{Binding Item2}" />
                    <GridViewColumn Header="Attribute value" DisplayMemberBinding="{Binding Item3}" />
                </GridView>
            </ListView.View>
        </ListView>
    </Grid>
</UserControl>
